//
//  ModeSelectLayer.m
//  SpeedTap
//
//  Created by Chi Ho Chiu on 18/12/11.
//  Copyright 2011 Individual. All rights reserved.
//

#import "ModeSelectLayer.h"


@implementation ModeSelectLayer
@synthesize delegate;

-(id) init
{
	if(self = [super init])
	{
		self.isTouchEnabled = YES;
		
		//Add background image
        CCSprite *bgSprite = [CCSprite spriteWithFile:@"mode.png"];
        [bgSprite setPosition:CGPointMake(240,160)];
        [self addChild:bgSprite z:0];
		
		//Add Story Sprite
		CCSprite *storySprite = [CCSprite node];
		[storySprite setOpacity:128];
		[storySprite setColor:ccc3(0, 250, 0)];
		[storySprite setTextureRect:CGRectMake(0, 0, 200, 115)];
		[storySprite setPosition:CGPointMake(225, 188)];
		[self addChild:storySprite z:1 tag:kMODE_SELECT_TAG_STORY];
		
		//Add Challenge Sprite
		CCSprite *challengeSprite = [CCSprite node];
		[challengeSprite setOpacity:128];
		[challengeSprite setColor:ccc3(0, 250, 0)];
		[challengeSprite setTextureRect:CGRectMake(0, 0, 200, 115)];
		[challengeSprite setPosition:CGPointMake(110, 80)];
		[self addChild:challengeSprite z:1 tag:kMODE_SELECT_TAG_CHALLENGE];
	}

	return self;
} 

-(void) dealloc
{
	[super dealloc];
}


#pragma mark - Touch Event
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
	UITouch* touch = [touches anyObject];
	CGPoint touchLocation =[[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
	
	if( CGRectContainsPoint([[self getChildByTag:kMODE_SELECT_TAG_STORY] boundingBox], touchLocation) )
	{
		[delegate onStoryModeSelected];
	}
	else if (CGRectContainsPoint([[self getChildByTag:kMODE_SELECT_TAG_STORY] boundingBox], touchLocation) )
	{
		[delegate onChallengeModeSelected];
	}
}


@end
